package com.woniuxy.ams.controller;


import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniuxy.ams.entity.AssessStandard;
import com.woniuxy.ams.entity.AssessType;
import com.woniuxy.ams.entity.PageRequest;
import com.woniuxy.ams.entity.ResultEntity;
import com.woniuxy.ams.service.AssessTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


/**
 * @author Zjp
 */
@RestController
@RequestMapping("/type")
public class AssessTypeController {

    @Autowired(required = false)
    AssessTypeService assessTypeService;


    /**
     * 查询考核种类表的所有数据
     *
     * @return 查询结果
     */
    @RequestMapping("/findAllAssessType")
    public ResultEntity<?> findAllAssessType(@RequestBody PageRequest<AssessType> pageRequest) {
        PageHelper.startPage(pageRequest.getCurrentPage(), pageRequest.getLimit());
         AssessType data = pageRequest.getData();
        List<AssessType> assessType = assessTypeService.findAllAssessType(data);
        PageInfo<AssessType> objectPageInfo = new PageInfo<>(assessType);
        if (assessType.size() != 0) {
            return new ResultEntity<>(200, "查询成功", objectPageInfo);
        }else {
            return new ResultEntity<>(200, "查询失败,没有数据", objectPageInfo);
        }
    }

    /**
     * 查找所有无分页
     * @return
     */
    @RequestMapping("/findAll")
    public ResultEntity<?> findAll() {
        List<AssessType> assessType = assessTypeService.findAll();
        if (assessType.size() != 0) {
            return new ResultEntity<>(200, "查询成功", assessType);
        }else {
            return new ResultEntity<>(200, "查询失败,没有数据", assessType);
        }
    }
    /**
     * 根据考核种类查询
     * @return
     */
    @RequestMapping("/findByAssessmentTypes")
    public ResultEntity<?> findByAssessmentTypes(@RequestBody AssessType pageRequest) {
      AssessType assessTypes = assessTypeService.findByAssessmentTypes(pageRequest);
        if (assessTypes!=null ) {
            return new ResultEntity<>(200, "查询成功", assessTypes);
        }else {
            return new ResultEntity<>(200, "查询失败,没有数据", assessTypes);
        }
    }

    /**
     * 添加assessType
     */
    @RequestMapping("/addAssessType")
    public ResultEntity<AssessType> addAssessType(@RequestBody AssessType assessType) {
        System.out.println(assessType);
        boolean i = assessTypeService.addAssessType(assessType);

        if (i) {
            return new ResultEntity<>(200, "添加成功", null);
        } else {
            return new ResultEntity<>(500, "添加失败", null);
        }
    }


    /**
     * 删除assessType
     */
    @RequestMapping("/deleteAssessType")
    public ResultEntity<AssessType> deleteAssessType(@RequestBody AssessType assessType) {
        boolean i = assessTypeService.deleteAssessType(assessType);

        if (i) {
            return new ResultEntity<>(200, "删除成功", null);
        } else {
            return new ResultEntity<>(500, "删除失败", null);
        }
    }


    /**
     * 修改assessType
     */
    @RequestMapping("/updateAssessType")
    public ResultEntity<AssessType> updateAssessType(@RequestBody AssessType assessType) {
        boolean i = assessTypeService.updateAssessType(assessType);

        if (i) {
            return new ResultEntity<>(200, "修改成功", null);
        } else {
            return new ResultEntity<>(500, "修改失败", null);
        }

    }

    /**
     *
     * 根据assessmentTypes查询
     * @param
     * @return
     */
    @RequestMapping("/findById")
    public ResultEntity<List<AssessType>> findById(@RequestBody AssessStandard assessStandard) {
        List<AssessType> assessTypes = assessTypeService.findById(assessStandard);
        if (assessTypes != null) {
            return new ResultEntity<>(200, "查询成功", assessTypes);
        }else {
            return new ResultEntity<>(500, "查询失败,没有此数据", null);
        }
    }


    @RequestMapping("/findByTypeId")
    public ResultEntity<List<AssessType>> findByTypeId(@RequestBody AssessType assessType) {
        System.out.println(assessType);
        List<AssessType> assessTypes = assessTypeService.findByTypeId(assessType);
        System.out.println(assessTypes);
        if (assessTypes != null) {
            return new ResultEntity<>(200, "查询成功", assessTypes);
        }else {
            return new ResultEntity<>(500, "查询失败,没有此数据", null);
        }
    }

}
